package com.mogu.biguser.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mogu.biguser.service.StatisticsService;
import com.mogu.biguser.service.dto.biguser.BigUser;
import com.mogu.biguser.service.dto.statistics.ParamTime;
import com.mogu.biguser.web.api.model.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/api/biguser/statistics")
public class StatisticsController {

    private static final Logger logger = LoggerFactory.getLogger(StatisticsController.class);
    @Resource
    public StatisticsService service;

    /**
     * 历史数据查询
     *
     * @param user
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public BaseResponse<PageInfo> index(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, BigUser user) {

        PageInfo pageInfo = null;
        try {
            PageHelper.startPage(pageNum, pageSize);
            pageInfo = service.findListStatisName(user);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new BaseResponse<PageInfo>(true, "历史数据查询", pageInfo);
    }

    /**
     * 日查询
     *
     * @param paramTime
     * @return
     */
    @RequestMapping(value = "/day", method = RequestMethod.POST)
    public BaseResponse<Map<String, Object>> day(ParamTime paramTime) {

        Map<String, Object> map = null;
        try {
            map = service.findListUserWaterday(paramTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new BaseResponse<Map<String, Object>>(true, "日查询", map);
    }

    /**
     * 月查询
     *
     * @param paramTime
     * @return
     */
    @RequestMapping(value = "/month", method = RequestMethod.POST)
    public BaseResponse<Map<String, Object>> month(ParamTime paramTime) {

        Map<String, Object> map = null;
        try {
            map = service.findListUserWaterMonth(paramTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new BaseResponse<Map<String, Object>>(true, "月查询", map);
    }



    /**
     * 年查询
     *
     * @param paramTime
     * @return
     */
    @RequestMapping(value = "/year", method = RequestMethod.POST)
    public BaseResponse<Map<String, Object>> year(ParamTime paramTime) {

        Map<String, Object> map = null;
        try {
            map = service.findListUserWaterYear(paramTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new BaseResponse<Map<String, Object>>(true, "年查询", map);
    }


    /**
     * 瞬时流量供水
     *
     * @param paramTime
     * @return
     */
    @RequestMapping(value = "/sinstant", method = RequestMethod.POST)
    public BaseResponse<Map<String, Object>> instant(ParamTime paramTime) {

        Map<String, Object> map = null;
        try {
            map = service.findListUserWaterInstant(paramTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new BaseResponse<Map<String, Object>>(true, "年查询", map);
    }


    /**
     * 瞬时排水
     *
     * @param paramTime
     * @return
     */
    @RequestMapping(value = "/dinstant", method = RequestMethod.POST)
    public BaseResponse<Map<String, Object>> dinstant(ParamTime paramTime) {

        Map<String, Object> map = null;
        try {
            map = service.findListUserWaterDInstant(paramTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new BaseResponse<Map<String, Object>>(true, "年查询", map);
    }



}
